<?php
include 'include/header.php';
?>
<div class="form-group">

				<table class="table" id="data">
				<?php
				if(!empty($data_csv))
				{
					$nomor = 0;
					//var_dump($data_csv);
					for($b = 0; $b < count($data_csv); $b++)
					{
						//var_dump($data_csv[$b]);
						//echo '<br />';
						
						if($b = 0){
						//echo '<tr>';
						//echo '<td>Nomor</td>';
						for($a = 0; $a < count($data_csv[$b]); $a++)
						{
							//echo '<td class="kolom" id="'.$data_csv[$b][$a].'">'.$data_csv[$b][$a].'</td>';	
							var_dump($data_csv[$b][$a]);
						}
						//echo '</tr>';
						} else{
							//var_dump($pertanyaan['pertanyaan']);
							/*$nomor++;
							echo '<tr id="row-'.$nomor.'">';
							echo '<td >'.$nomor.'</td>';
							for($c = 0; $c < count($data_csv[$b]); $c++)
							{
								echo '<td class="'.$c.'">'.$data_csv[$b][$c].'</td>';
							}
							echo '</tr>';*/
						
						}
					}
				} else
					{
						echo 'belum ada data responden';
					}
				?>
				</table>
</div>
<?php
if(!empty($data_csv))
{
?>
<div>
	<button onclick="test()">Uji Data</button>
</div>
<?php
}
?>
<div class="modal" id="ajaxModal">
	<div class="modal-body">
		<div class="modal-dialog" style="width: 1275px;">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Uji Data</h4>
				</div>
				<div class="modal-body" id="kolom_variabel">
					
				</div>
				<div class="modal-body" id="kolom_ujidata">
					
				</div>
				<div class="modal-body">
				<select id="jenis_uji">
					<option value="0">Reliabilitas</option>
					<option value="1">Validitas</option>
				</select>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn_uji" class="btn btn-default" onclick="uji()" disabled>Uji</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				</div>
			</div>
		</div>
	</div>
</div>
		
		
<script>

</script>
<script>
$(document).ready(function(){
	
})

var i;
var a = [];
var d = [];


function delete_responden(id_resp,id,e)
	{
	
	var x = confirm('Anda yakin akan menghapus data ini?');
	if(x){
		$.post('<?php echo base_url(); ?>index.php/uji/delete_responden/', {
				id_responden: id_resp
			});
			$('#row-'+id).remove();
		} else{e.preventDefault();}
	
	} 

function test()
	{
		var b = 0;
		var c = 0;
		$('.kolom').each(function(){
			a[b++] = $(this).text();
			d[c++] = $(this).attr('id');
		});
				
		//console.log(d);
		var html='';
		$('.var_uji').remove();	
		for (i = 0; i < a.length; i++) { 
		$('#variabel-'+i).remove();			
		html += '<div>';
		if(d[i] == '1' || d[i] == '2'){
		html += '<button hidden>'+a[i]+'</button>';
		} else{
			html += '<button id="variabel-'+i+'" onclick="insert_var('+i+')">'+a[i]+'</button>';
		}
		html += '</div>';
		
		}
		
		$('#kolom_variabel').append(html);
		$('#ajaxModal').modal('show');
	}

function insert_var(variabel)
{
	var html = '<button id="var_uji-'+variabel+'" class="var_uji" onclick="delete_var_uji('+variabel+')">'+a[variabel]+'</button>';
	$('#variabel-'+variabel).css('display', 'none');
	$('#kolom_ujidata').append(html);
	if($('.var_uji').length > 1){
		$('#btn_uji').removeAttr('disabled');
	}
}

function delete_var_uji(variabel){
	$('#variabel-'+variabel).css('display', 'block');
	$('#var_uji-'+variabel).remove();
	if($('.var_uji').length <= 1){
		$('#btn_uji').attr('disabled', 'disabled');
	}
}

function uji()
{

	if($('#jenis_uji').val() == '0')
	{
	
		var c = 0;
		var var_uji = [];
		//var non_integer = 'false';
		$('.var_uji').each(function(){
			var_uji[c++] = $(this).prop('id').replace( /[^\d.]/g, '' );
		});
		//console.log(var_uji.length);
		var data = new Array(var_uji.length);
		for(var d = 0; d < var_uji.length; d++){
			//console.log(var_uji[d]);
			var e = 0;
			data[d] = new Array($('.'+var_uji[d]).length);
			$('.'+var_uji[d]).each(function(){
				data[d][e++] = parseInt($(this).text());
			});
		}
		
			$.ajax({
				url: '<?php echo base_url(); ?>index.php/uji/reliabilitas/',
				data: {'data' : data},
				type: 'post',
				success: function(data) {
									alert(data);
									var reliabel = confirm('apakah data reliabel?', 'Ya', 'Tidak');
									if(!reliabel){return false;
									} else{
										$.post('<?php echo base_url(); ?>index.php/uji/tanda_reliabel/', {
											id_kuesioner: $('#id_kuesioner').val()
										});
										}
								}
			});
		
		
	} else { 
			var c = 0;
			var var_uji = [];
			//var non_integer = 'false';
			$('.var_uji').each(function(){
				var_uji[c++] = $(this).prop('id').replace( /[^\d.]/g, '' );
			});
			//console.log(var_uji.length);
			var data = new Array(var_uji.length);
			for(var d = 0; d < var_uji.length; d++){
				//console.log(var_uji[d]);
				var e = 0;
				data[d] = new Array($('.'+var_uji[d]).length);
				$('.'+var_uji[d]).each(function(){
					data[d][e++] = parseInt($(this).text());
				});
			}
			
				$.ajax({
					url: '<?php echo base_url(); ?>index.php/uji/validitas/',
					data: {'data' : data},
					type: 'post',
					success: function(data) {
										alert(data);
									}
				});
		}
} 

</script>
<?php
include 'include/footer.php';
?>